/**
 * Simple edit control.
 *
 * @author Andrey Anisimov <hercules@inbox.ru>
 */

import core.ui.InputWindow;

class Edit extends InputWindow {

	/**
	 * Creates new edit control.
	 * 
	 * @param parent (Window) [optional] parent window
	 * @param x, y (int) [optional] coordinates
	 * @param width, height (int) [optional] control size.
	 */		
	this.Edit = function(parent, x, y, width, height) {
		super(parent, x, y, width, height);
		
		// FIX: When the input gained focus and then lost it, the folowing error occurs in Mozilla:
		// "Permission denied to set property XULElement.selectedIndex' when calling method: [nsIAutoCompletePopup::selectedIndex]" 
		this.getInput().setAttribute('autocomplete', 'off');
		
		// FIX: Provide text selection for IE4+
		if (this.getInput().onselectstart) {
			this.getInput().onselectstart = new Function('window.event.cancelBubble = true');
		}
	}
	
	/**
	 * Sets whether this control should be read-only.
	 *
	 * @param readOnly (bool) true if read only, false otherwise.
	 */
	this.setReadOnly = function(readOnly) {
		this.getElement().readOnly = readOnly;
	}
	
	/**
	 * Returns whether this control is read only.
	 *
	 * @return bool
	 */
	this.isReadOnly = function() {
		return this.getElement().readOnly;
	}
	
	/**
	 * @protected
	 * Gets the type of input element.
	 *
	 * @return string
	 */
	this.getType = function() {
		return 'text';
	}
}